import {
  _decorator,
  AudioClip,
  director,
  EventMouse,
  instantiate,
  Node,
  Prefab,
} from "cc";
import { SceneType } from "../model";
import { RenderManager } from "../base/render-manager";
import { DataManager } from "../runtime/data-manager";
const { ccclass, property } = _decorator;

@ccclass("BaseSceneManager")
export class BaseSceneManager extends RenderManager {
  @property(AudioClip)
  bgm: AudioClip = null;

  @property({ type: Prefab, tooltip: "背包预制体" })
  packPrefab: Prefab = null;

  @property({ type: Node, tooltip: "道具容器" })
  items: Node = null;
  changeScene(event: EventMouse, sceneType: SceneType) {
    director.loadScene(sceneType);
  }

  start() {
    super.start();

    if (this.packPrefab) {
      const pack = instantiate(this.packPrefab);
      this.node.parent.addChild(pack);
    }

    if (this.bgm && !DataManager.Instance.isAudioPlaying) {
      DataManager.Instance.playAudio(this.bgm);
    }
  }

  render() {}
}
